package com.gxuwz.zhangjiahui.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxuwz.zhangjiahui.entity.Budget;
import com.gxuwz.zhangjiahui.entity.Conclusion;
import com.gxuwz.zhangjiahui.entity.Echarts;
import com.gxuwz.zhangjiahui.entity.Project;
import com.gxuwz.zhangjiahui.service.IBudgetService;
import com.gxuwz.zhangjiahui.service.IConclusionService;
import com.gxuwz.zhangjiahui.service.IEnclosureService;
import com.gxuwz.zhangjiahui.service.IProjectService;
import org.apache.ibatis.annotations.Param;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangjiahui
 * @since 2021-06-20
 */
@Controller
@RequestMapping("/echarts")
public class EchartsController {

    @Autowired
    private IProjectService iProjectService;
    @Autowired
    private IConclusionService iConclusionService;

    /**
     * 显示页面
     * @return
     */
    @GetMapping(value = "/findEcharts")
    public ModelAndView findEcharts(ModelAndView modelAndView) {
        modelAndView.setViewName("/echarts/echarts_list");
        return modelAndView;
    }

    /**
     * 表格统计
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/echartsNow")
    public List<Echarts> echartsNow() {
        // 查询全部竞赛申报人数
        List<Project> projectList = iProjectService.findProjectAll();
        // 查询全部结题人数
        List<Conclusion> conclusionList = iConclusionService.findConclusionAll();

        List<Echarts> echartsList = new ArrayList<>(projectList.size());

        List<Conclusion> conclusionListAwards = new ArrayList<>(conclusionList.size());
        // 统计获奖人数
        for(int i=0; i<conclusionList.size(); i++){
            // 结题审批通过
            if(conclusionList.get(i).getApprovalStateOne() != null && conclusionList.get(i).getApprovalStateOne() == 1){
                if(conclusionList.get(i).getAwardsState() != null && conclusionList.get(i).getAwardsState() != 6){
                    conclusionListAwards.add(conclusionList.get(i));
                }
            }
        }

        // 输出
        System.out.println("projectList = " + projectList);
        System.out.println("conclusionList = " + conclusionList);
        System.out.println("conclusionListAwards = " + conclusionListAwards);

        // 存放数据
        Echarts echarts = new Echarts();
        echarts.setName("竞赛报名总人数");
        echarts.setValue(projectList.size());
        echartsList.add(echarts);

        Echarts echarts1 = new Echarts();
        echarts1.setName("竞赛获奖总人数");
        echarts1.setValue(conclusionList.size());
        echartsList.add(echarts1);

        Echarts echarts2 = new Echarts();
        echarts2.setName("竞赛结题总人数");
        echarts2.setValue(conclusionListAwards.size());
        echartsList.add(echarts2);

        return echartsList;

    }


    /**
     * 表格统计2
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/echartsNowSo")
    public List<Echarts> echartsNowSo() {
        // 查询全部竞赛申报人数
        List<Project> projectList = iProjectService.findProjectAll();
        // 查询全部结题人数
        List<Conclusion> conclusionList = iConclusionService.findConclusionAll();

        List<Echarts> echartsList = new ArrayList<>(projectList.size());

        List<Conclusion> conclusionListAwards = new ArrayList<>(conclusionList.size());

        List<Conclusion> conclusionListAwards1 = new ArrayList<>(conclusionList.size());
        List<Conclusion> conclusionListAwards2 = new ArrayList<>(conclusionList.size());
        List<Conclusion> conclusionListAwards3 = new ArrayList<>(conclusionList.size());
        List<Conclusion> conclusionListAwards4 = new ArrayList<>(conclusionList.size());
        List<Conclusion> conclusionListAwards5 = new ArrayList<>(conclusionList.size());
        List<Conclusion> conclusionListAwards6 = new ArrayList<>(conclusionList.size());

        // 统计获奖类型人数
        for(int i=0; i<conclusionList.size(); i++) {
            // 结题审批通过
            if (conclusionList.get(i).getApprovalStateOne() != null && conclusionList.get(i).getApprovalStateOne() == 1) {
                if (conclusionList.get(i).getAwardsState() != null) {
                    if (conclusionList.get(i).getAwardsState() == 1) {
                        conclusionListAwards1.add(conclusionList.get(i));
                    } else if (conclusionList.get(i).getAwardsState() == 2) {
                        conclusionListAwards2.add(conclusionList.get(i));
                    } else if (conclusionList.get(i).getAwardsState() == 3) {
                        conclusionListAwards3.add(conclusionList.get(i));
                    } else if (conclusionList.get(i).getAwardsState() == 4) {
                        conclusionListAwards4.add(conclusionList.get(i));
                    } else if (conclusionList.get(i).getAwardsState() == 5) {
                        conclusionListAwards5.add(conclusionList.get(i));
                    } else if (conclusionList.get(i).getAwardsState() == 6) {
                        conclusionListAwards6.add(conclusionList.get(i));
                    }
                }
            }

        }

        // 输出
        System.out.println("projectList = " + projectList);
        System.out.println("conclusionList = " + conclusionList);
        System.out.println("conclusionListAwards1 = " + conclusionListAwards1);
        System.out.println("conclusionListAwards2 = " + conclusionListAwards2);
        System.out.println("conclusionListAwards3 = " + conclusionListAwards3);
        System.out.println("conclusionListAwards4 = " + conclusionListAwards4);
        System.out.println("conclusionListAwards5 = " + conclusionListAwards5);
        System.out.println("conclusionListAwards6 = " + conclusionListAwards6);

        // 存放数据
        Echarts echarts = new Echarts();
        echarts.setName("特等奖人数");
        echarts.setValue(conclusionListAwards1.size());
        echartsList.add(echarts);

        Echarts echarts1 = new Echarts();
        echarts1.setName("一等奖人数");
        echarts1.setValue(conclusionListAwards2.size());
        echartsList.add(echarts1);

        Echarts echarts2 = new Echarts();
        echarts2.setName("二等奖人数");
        echarts2.setValue(conclusionListAwards3.size());
        echartsList.add(echarts2);

        Echarts echarts3 = new Echarts();
        echarts3.setName("三等奖人数");
        echarts3.setValue(conclusionListAwards4.size());
        echartsList.add(echarts3);

        Echarts echarts4 = new Echarts();
        echarts4.setName("优秀奖人数");
        echarts4.setValue(conclusionListAwards5.size());
        echartsList.add(echarts4);

        Echarts echarts5 = new Echarts();
        echarts5.setName("未获奖人数");
        echarts5.setValue(conclusionListAwards6.size());
        echartsList.add(echarts5);

        return echartsList;

    }


}
